package com.ebook.core.util;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ebook.core.domain.Note;

public class NoteUtil {
	
	private static Log logger = LogFactory.getLog(NoteUtil.class); 

	/**
	 * 从map中读取内容解析一个笔记书签的基本信息(map一般是查询数据库返回的结果)
	 * @param map
	 * @return book如果正常，否则返回null
	 */

	public static Note parseNote(Map<String, Object> map) {
		try {
			Integer uid = (Integer)map.get("uid") == null ? 0 : (Integer)map.get("uid") ;
			Integer bookid = (Integer)map.get("bookid") == null ? 0 : (Integer)map.get("bookid") ;
			String noteid = (String)map.get("noteid") == null ? null : (String)map.get("noteid") ;
			Long create_time = (Long)map.get("create_time") == null ? 0 : (Long)map.get("create_time") ;
			Long update_time = (Long)map.get("update_time") == null ? 0 : (Long)map.get("update_time") ;
			Long upload_time = (Long)map.get("upload_time") == null ? 0 : (Long)map.get("upload_time") ;
			Integer curr_chapter = (Integer)map.get("curr_chapter") == null ? 0 : (Integer)map.get("curr_chapter") ;
			String select_content = (String)map.get("select_content") == null ? null : (String)map.get("select_content") ;
			String note_content = (String)map.get("note_content") == null ? null : (String)map.get("note_content") ;
			Integer issynronezed = (Integer)map.get("issynronezed") == null ? 0 : (Integer)map.get("issynronezed") ;
			Integer contain_file = (Integer)map.get("contain_file") == null ? 0 : (Integer)map.get("contain_file") ;
			String startCFI = (String)map.get("startCFI") == null ? null : (String)map.get("startCFI") ;
			String endCFI = (String)map.get("endCFI") == null ? null : (String)map.get("endCFI") ;
			Integer note_index = (Integer)map.get("note_index") == null ? 0 : (Integer)map.get("note_index") ;
			Integer isNote = (Integer)map.get("isNote") == null ? 0 : (Integer)map.get("isNote") ;
			String color = (String)map.get("color") == null ? null : (String)map.get("color") ;
			Integer isExist = (Integer)map.get("isExist") == null ? 0 : (Integer)map.get("isExist") ;
			String chapter_title = (String)map.get("chapter_title") == null ? null : (String)map.get("chapter_title") ;
			String flag = map.containsKey("flag") ? (String)map.get("flag") : "";
			String noteIdsAndFlag = map.containsKey("noteIdsAndFlag") ? (String)map.get("noteIdsAndFlag") : "";
			return new Note(uid,bookid,noteid,create_time,
					update_time, upload_time,curr_chapter,
					startCFI, endCFI,isNote, isExist,
					flag,noteIdsAndFlag,note_content,
					issynronezed, contain_file, note_index, color,
					 chapter_title, select_content);
		} catch (Exception e) {
			logger.error("创建  Note 对象失败" + e.getMessage());
			return null;
		}	
	}

}
